package com.software.controller;


import com.software.base.ResultInfo;
import com.software.bean.CustomerInfoBean;
import com.software.dto.CustomerLoginDto;
import com.software.dto.CustomerRegisterDto;
import com.software.dto.CustomerReturnPwdDto;
import com.software.dto.UpdatePasswordDto;
import com.software.service.CustomerLoginService;
import com.software.utils.AssertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wyj
 * @since 2024-03-19
 */
@RequestMapping("/customerLogin")
@Controller
public class CustomerLoginController {

    @Autowired
    private CustomerLoginService customerLoginService;

    // 登录
    @PostMapping("/front/login")
    @ResponseBody
    public ResultInfo login(@RequestBody CustomerLoginDto customerLoginDto) {
        CustomerInfoBean customerInfoBean = customerLoginService.login(customerLoginDto);
        AssertUtil.isTrue(customerInfoBean == null, "登录失败");
        return ResultInfo.success(customerInfoBean);
    }

    /**
     * @description:前端注册
     * @author: wyj
     * @date: 2024/3/20 21:27
     * @param:
     * @return:
     */
    @PostMapping("/front/register")
    @ResponseBody
    public ResultInfo register(@RequestBody CustomerRegisterDto registerDto) {
        Integer result = customerLoginService.register(registerDto);
        AssertUtil.isTrue(result != 1, "插入失败2");
        return ResultInfo.success();
    }

    /**
     * @description:用户修改密码
     * @author: wyj
     * @date: 2024/3/30 21:40
     * @param:
     * @return:
     */
    @PostMapping("/front/updatePassword")
    @ResponseBody
    public ResultInfo updatePassword(@RequestBody UpdatePasswordDto updatePasswordDto) {
        Integer result = customerLoginService.updatePassword(updatePasswordDto);
        AssertUtil.isTrue(result != 1, "更新失败");
        return ResultInfo.success();
    }


    @PostMapping("/front/returnPwd")
    @ResponseBody
    public ResultInfo returnPwd(@RequestBody CustomerReturnPwdDto returnPwdDto) {
        Integer result = customerLoginService.returnPwd(returnPwdDto);
        AssertUtil.isTrue(result != 1, "修改失败");
        return ResultInfo.success();
    }
}
